package cn.com.jtang.wedding.util;

import java.security.MessageDigest;

public class EncryptUtil {
	
    public static String Encrypt(String secret)
    {
        String result = null;

        try
        {
            MessageDigest md = MessageDigest.getInstance("MD5");
            result = byte2hex(md.digest(secret.toString().getBytes("utf-8")));
        }
        catch(Exception ex)
        {
            throw new java.lang.RuntimeException("encrypt error !");
        }

        return result;
    }

    private static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1)
                hs = hs + "0" + stmp;
            else
                hs = hs + stmp;
        }
        return hs.toUpperCase();

    }
    
}
